package com.fedming.bottomnavigationdemo.Util;

import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.os.Build;

import com.fedming.bottomnavigationdemo.HomeActivity;

public class CameraUtils {
    //查询是否有摄像头
    public static boolean hasCamera(Context context){
        boolean hasCamera=false;
        PackageManager pm= context.getPackageManager();
        hasCamera=pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)||pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)||
                Build.VERSION.SDK_INT<Build.VERSION_CODES.GINGERBREAD|| Camera.getNumberOfCameras()>0;
        return hasCamera;
    }
    //查询相机是否可用
    public static boolean isCameraCanUse() {
        boolean canUse = true;
        Camera mCamera = null;
        try {
            mCamera = Camera.open(0);
            mCamera.setDisplayOrientation(180);
        } catch (Exception e) {
            canUse = false;
        }
        if (canUse) {
            mCamera.release();
            mCamera = null;
        }
        //Timber.v("isCameraCanuse="+canUse);
        return canUse;
    }
}
